#include <stdio.h>

#define DEBUG

char isbn[11];

int times = -1;

int ch2int(char ch)
{
	if (ch == 'X')
		return 10;
	else
		return ch - '0';
}

char int2ch(int val)
{
	if (val == 10)
		return 'X';
	else
		return '0' + val;
}

void find()
{
	int i = 0;
	int sum = 0;
	for (i = 0; i < 10; ++i)
	{
		char ch = isbn[9-i];
#ifdef DEBUG
		printf("i: %d ch: %c\n", i, ch);
#endif
		if (ch != '?')
		{
			sum += ((i+1)*ch2int(ch));
		}
		else
			times = i+1;
	}	
#ifdef DEBUG
	printf("times= %d\n", times);
#endif

	int max_value = 0;
	if (times == 1)// ? at last digit
		max_value = 10;
	else
		max_value = 9;
	for (i = 0; i <= max_value; ++i)
	{
		if ((sum  + (times * i)) % 11 == 0)
		{
			printf("%c\n", int2ch(i));
			return;
		}
	}
	printf("-1\n");
	return;
	
}

int main(void)
{
#ifdef DEBUG
	freopen("bin/2190.in", "r", stdin);
#endif

	scanf("%s", isbn);
#ifdef DEBUG
	printf("%s\n", isbn);
#endif

	find();

	return 0;
}
